/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.gwt.basics.client.widget.richtext;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * This class create a Rich text editing.
 */
public class RichTextWidget
    extends Composite
{

  /**
   * String representing the full size in HTML.
   */
  private static final String FULL_SIZE = "100%";

  /**
   * a RichTextArea.
   */
  private final transient RichTextArea bodyWidget;



  /**
   * constructors.
   * 
   * @param bodyWidget
   *          a RichTextArea.
   */
  public RichTextWidget(final RichTextArea bodyWidget)
  {

    this.bodyWidget = bodyWidget;

    final VerticalPanel top = new VerticalPanel();
    top.setWidth(FULL_SIZE);

    final HorizontalPanel controls = new HorizontalPanel();
    final RichTextToolBar toolBar = new RichTextToolBar(this.bodyWidget);

    controls.add(toolBar);
    controls.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    controls.setWidth(FULL_SIZE);

    top.add(controls);

    top.add(bodyWidget);
    this.bodyWidget.setWidth(FULL_SIZE);
    this.bodyWidget.setHeight(FULL_SIZE);

    initWidget(top);
  }



  /**
   * Retrieves the current text stored in the UI widget.
   * 
   * @return the current text in the UI
   */
  public String getHTML()
  {
    return bodyWidget.getHTML();
  }



  /**
   * Sets the content of the textbox to the specified value.
   * 
   * @param newText
   *          the new content of the textbox
   */
  public void setHTML(final String newText)
  {
    bodyWidget.setHTML(newText);
  }

}
